package com.his.dao.jpa;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import com.his.pojos.jpa.HisOperationApparatus;

public interface MxjOperationApparatusDAO extends CrudRepository<HisOperationApparatus, Long>{

	@Query("select max(ssqxNo) from HisOperationApparatus ")
	public String findOpApparatusMaxId();
	
	@Query("select ssqxNo from HisOperationApparatus where ssqxNo=:ssqxNo")
	public String findByssqxNo(@Param("ssqxNo")long ssqxNo);
	
	@Query("select count(*) from HisOperationApparatus oa,HisTakeinstrument ti "
			+ "where oa.qcNo=ti.qcNo and ti.ssNo=:ssNo "
			+ " order by oa.ssqxNo asc")
	public String counts(@Param("ssNo")BigDecimal ssNo);
	
	@Query("select oa from HisOperationApparatus oa,HisTakeinstrument ti "
			+ "where oa.qcNo=ti.qcNo and ti.ssNo=:ssNo "
			+ " order by oa.ssqxNo asc")
	public List<HisOperationApparatus>findAllOperationApparatusByPage(Pageable pageable,@Param("ssNo")BigDecimal ssNo);

	@Query("select sum(oa.cpPrice) from HisOperationApparatus oa, HisTakeinstrument tt where "
			+ "tt.qcNo=oa.qcNo and tt.ssNo=:ssNo")
	public BigDecimal findapPriceByssNo(@Param("ssNo")BigDecimal ssNo);
	
	@Query("select oa from HisOperationApparatus oa,HisTakeinstrument tt"
			+ " where oa.qcNo=tt.qcNo and tt.ssNo=:ssNo and oa.cpName=:cpName")
	public HisOperationApparatus inspectHisOperationApparatusByssNo(@Param("ssNo")BigDecimal ssNo,@Param("cpName")String cpName);
}
